<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category SettingConfigTabController.php
 * @Depiction: 基础配置-配置分类
 * Author: hwy
 * Date: 2020/9/30  16:20
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\SettingConfigTab\Store;
use App\Services\SettingConfigTabService;
use Illuminate\Http\Request;

class SettingConfigTabController extends Controller
{
    protected $_model = 'setting_config_tab';

    protected $settingConfigTabService;

    public function __construct()
    {
        $this->settingConfigTabService = SettingConfigTabService::getInstance();
    }

    /**
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @Depiction 列表页
     * @Author hwy
     * @Date  2021/2/20  10:48
     */
    public function index(Request $request)
    {
        $compact = compact('request');

        return view('admin.' . $this->_model . '.index', $compact);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @Depiction 列表页内容
     * @Author hwy
     * @Date  2021/2/20  11:02
     */
    public function getList(Request $request)
    {
        $responseData = $this->settingConfigTabService->getList($request);

        return response()->json($responseData);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @Depiction
     * @Author hwy
     * @Date  2021/2/20  11:04
     */
    public function create(Request $request)
    {
        $config_category_tab_type = config('other.config_category_type');
        $compact                  = compact('request', 'config_category_tab_type');

        return view('admin.' . $this->_model . '.create', $compact);
    }

    /**
     * @param Store $request
     * @return \Illuminate\Http\JsonResponse
     * @Depiction
     * @Author hwy
     * @Date  2021/2/20  11:04
     */
    public function store(Store $request)
    {
        $responseData = $this->settingConfigTabService->addData($request);

        return response()->json($responseData);
    }

    /**
     * @param Request $request
     * @param $id
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @Depiction
     * @Author hwy
     * @Date  2020/9/30  16:28
     */
    public function edit(Request $request, $id)
    {
        $config_category_tab_type = config('other.config_category_type');
        $data                     = $this->settingConfigTabService->getOne($id);

        $compact = compact('request', 'data', 'config_category_tab_type');

        return view('admin.' . $this->_model . '.edit', $compact);

    }

    /**
     * @param Store $request
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     * @Depiction
     * @Author hwy
     * @Date  2020/10/10  19:27
     */
    public function update(Store $request, $id)
    {
        $responseData = $this->settingConfigTabService->editData($request, $id);

        return response()->json($responseData);
    }

    /**
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     * @Depiction
     * @Author hwy
     * @Date  2020/10/10  19:27
     */
    public function destroy($id)
    {
        $responseData = $this->settingConfigTabService->delData($id);

        return response()->json($responseData);
    }

    /**
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     * @Depiction
     * @Author hwy
     * @Date  2020/10/10  19:28
     */
    public function setStatus($id)
    {
        $responseData = $this->settingConfigTabService->setStatus($id);

        return response()->json($responseData);
    }

}
